import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom';
import { LanguageProvider } from '@kernelproxy/i18n';
import { ThemeProvider } from '@kernelproxy/theme';
import { AuthProvider } from './contexts/AuthContext';
import { CartProvider } from './contexts/CartContext';
import { ToastProvider } from './contexts/ToastContext';
import ProtectedRoute from './components/ProtectedRoute';
import Login from './pages/Login';
import Register from './pages/Register';
import Dashboard from './pages/Dashboard';
import TermsOfService from './pages/TermsOfService';
import PrivacyPolicy from './pages/PrivacyPolicy';
import AuthCallback from './pages/AuthCallback';
import ForgotPassword from './pages/ForgotPassword';
import ResetPassword from './pages/ResetPassword';
import VerifyEmail from './pages/VerifyEmail';
import MFASettings from './pages/MFASettings';
import MFAVerify from './pages/MFAVerify';
import SessionManagement from './pages/SessionManagement';

function App() {
  return (
    <BrowserRouter>
      <ThemeProvider>
        <LanguageProvider>
          <ToastProvider>
            <CartProvider>
              <AuthProvider>
                <Routes>
                <Route path="/" element={<Navigate to="/login" replace />} />
                <Route path="/login" element={<Login />} />
                <Route path="/register" element={<Register />} />
                <Route path="/forgot-password" element={<ForgotPassword />} />
                <Route path="/reset-password" element={<ResetPassword />} />
                <Route path="/verify-email" element={<VerifyEmail />} />
                <Route path="/mfa/verify" element={<MFAVerify />} />
                <Route path="/auth/callback" element={<AuthCallback />} />
                <Route path="/dashboard/*" element={
                  <ProtectedRoute>
                    <Dashboard />
                  </ProtectedRoute>
                } />
                <Route path="/settings/mfa" element={
                  <ProtectedRoute>
                    <MFASettings />
                  </ProtectedRoute>
                } />
                <Route path="/settings/sessions" element={
                  <ProtectedRoute>
                    <SessionManagement />
                  </ProtectedRoute>
                } />
                <Route path="/terms-of-service" element={<TermsOfService />} />
                <Route path="/privacy-policy" element={<PrivacyPolicy />} />
                
                {/* Chinese routes */}
                <Route path="/zh-CN" element={<Navigate to="/zh-CN/login" replace />} />
                <Route path="/zh-CN/login" element={<Login />} />
                <Route path="/zh-CN/register" element={<Register />} />
                <Route path="/zh-CN/forgot-password" element={<ForgotPassword />} />
                <Route path="/zh-CN/reset-password" element={<ResetPassword />} />
                <Route path="/zh-CN/verify-email" element={<VerifyEmail />} />
                <Route path="/zh-CN/mfa/verify" element={<MFAVerify />} />
                <Route path="/zh-CN/auth/callback" element={<AuthCallback />} />
                <Route path="/zh-CN/dashboard/*" element={
                  <ProtectedRoute>
                    <Dashboard />
                  </ProtectedRoute>
                } />
                <Route path="/zh-CN/settings/mfa" element={
                  <ProtectedRoute>
                    <MFASettings />
                  </ProtectedRoute>
                } />
                <Route path="/zh-CN/settings/sessions" element={
                  <ProtectedRoute>
                    <SessionManagement />
                  </ProtectedRoute>
                } />
                <Route path="/zh-CN/terms-of-service" element={<TermsOfService />} />
                <Route path="/zh-CN/privacy-policy" element={<PrivacyPolicy />} />
              </Routes>
            </AuthProvider>
          </CartProvider>
          </ToastProvider>
        </LanguageProvider>
      </ThemeProvider>
    </BrowserRouter>
  );
}

export default App;
